﻿using DomainService.IService;
using Microsoft.AspNetCore.Mvc;
using Utility.Enum;
using Model.DomainModel;
using Utility;
using Model.BusinessModel.OutPut;
using Model.BusinessModel;
using Model.BusinessModel.InPut;

namespace ApprovalFlow_WebApi.Controllers
{
    /// <summary>
    /// 表单模块
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    [ApiExplorerSettings(GroupName = nameof(ModeuleGroupEnum.Form))]
    public class FormController : BaseController
    {
        #region 构造实列化

        /// <summary>
        /// 表单服务
        /// </summary>
        public IFormService _formService;


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="formService"></param>
        public FormController(IFormService formService)
        {
            _formService = formService;
        }

        #endregion

        #region 接口

        /// <summary>
        /// 新增表单
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        [HttpPost]
        public ReceiveStatus Insert(Form form)
        {
            form.CreateTime = DateTime.Now;
            form.CreateUserKey = GetLoginUserMsg().UserId.ToString();
            return _formService.Insert(form);
        }

        /// <summary>
        /// 更新表单信息
        /// </summary>
        /// <param name="form">实体模型</param>
        /// <returns></returns>
        [HttpPost]
        public ReceiveStatus Update(Form form)
        {
            form.CreateTime = DateTime.Now;
            form.CreateUserKey = GetLoginUserMsg().UserId.ToString();
            return _formService.Update(form);
        }

        /// <summary>
        /// 获取所有表单
        /// </summary>
        /// <param name="pageResultModel">分页参数模型</param>
        /// <returns></returns>
        [HttpPost]
        public ReceiveStatus<List<FormOutPut>> GetAllForm(PageResultModel pageResultModel)
        {
            ReceiveStatus<List<FormOutPut>> receiveStatus = new();
            var result = _formService.GetAllForm(pageResultModel);
            receiveStatus.data = result.data;
            receiveStatus.total = result.total;
            return receiveStatus;
        }

        /// <summary>
        /// 根据主键获取表单
        /// </summary>
        /// <param name="formId">表单主键</param>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<Form> GetFormByFormId(string formId)
        {
            return _formService.GetFormByFormId(formId);
        }

        /// <summary>
        /// 根据表单主键获取字段
        /// </summary>
        /// <param name="formId">表单kye</param>
        /// <returns>返回表单字段</returns>
        [HttpGet]
        public ReceiveStatus<List<SelectOutPut>> GetFormField(string formId)
        {
            return _formService.GetFormField(formId);
        }
        /// <summary>
        /// 根据部门ID,获取表单
        /// </summary>
        /// <param name="departmentId">部门id</param>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<List<TreeOutPut>> GetFormByDepId(string departmentId)
        {
            return _formService.GetFormByDepId(departmentId);
        }

        /// <summary>
        /// 更新数据状态
        /// </summary>
        /// <param name="input">输入模型</param>
        /// <returns></returns>
        [HttpPost]
        public ReceiveStatus UpdateFormDataState(UpdateDataStateInput input)
        {
            return _formService.UpdateFormDataState(input);
        }
        #endregion
    }
}
